package es.ats.codington.festival.services;

import java.sql.SQLException;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import es.ats.codington.festival.daos.ManagerDAO;
import es.ats.codington.festival.domain.Event;

import es.ats.codington.festival.exceptions.ServiceException;
import es.ats.codington.festival.interfaces.daos.IEventDAO;

import es.ats.codington.festival.interfaces.services.IEventService;
/**
 * 
 * @author Codington_RED
 *
 */

public class EventService implements IEventService{

	
	private IEventDAO eventDAO;
	
	public EventService(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");  
		ManagerDAO daoManager = (ManagerDAO) ctx.getBean("daoManager");
		this.eventDAO = daoManager.getEventDAO();
	}
	
	/**
	 * method that gets a list of events from database
	 * @return eventDAO.showAllEvents
	 * @throws ServiceException
	 */
	
	@Override
    public List<Event> getAllEvents() throws ServiceException {	
	
		return eventDAO.showAllEvents();
		
		
    }
	
	/**
	 * method that gets a list of events from database using the EventName
	 * @param eventName
	 * @return eventDAO.showAllEvents(eventName)
	 * @throws ServiceException
	 */
    @Override
    public List<Event> getAllEvents(Event eventName) throws ServiceException {	
    	
    	return eventDAO.showEvents(eventName);
	
    }

    /**
     * method that checks if does exits an event
     * @param event
     * @return eventDAO.getCheckEvent(event)
     * @throws ServiceException
     * @throws SQLException
     */
    @Override
    public boolean checkEvent(Event event) throws ServiceException, SQLException {
    	
    	return eventDAO.getCheckEvent(event);
    	
	}
    
    /**
     * method that obtains an event taking the event id
     * @param eventId
     * @return event
     * @throws ServiceException 
     */
    @Override
    public Event getEvent(int eventId) throws ServiceException {
    	
    	return eventDAO.getEvent(eventId);
	
	 }

    /**
     * method that obtains the eventId
     * @param event
     * @return eventDAO.getEvent(eventId)
     * @throws ServiceException
     * @throws SQLException
     */
    @Override
    public int getIdEvent(Event event) throws ServiceException, SQLException {
    	
    	return eventDAO.getIdEvent(event);
  
    }
    
    /**
     * method that modifies all the information relative to an event
     * @param event
     * @return eventDAO.updateEvent(event)
     * @throws ServiceException 
     */
    @Override
    public int updateEvent(Event event) throws ServiceException {
	
    	return eventDAO.updateEvent(event);
    	
    }

   

    
    /**
     * method that inserts an event into the database
     * @param event
     * @return eventDAO.insertEvent(event)
     * @throws ServiceException
     */
    @Override
    public boolean insertEvent(Event event) throws ServiceException{
    	
    	return eventDAO.insertEvent(event);
	
    }
    
    
    /**
     * method that updates the number of seats available for the event
     * @param event
     * @return eventDAO.updateSeatsEventDec(event)
     * @throws ServiceException
     */
    @Override
    public int updateSeatsEventDec(Event event) throws ServiceException {
    	
    	return eventDAO.updateSeatsEventDec(event);
    	
    }
    
    
    /**
     * method that updates the number of seats available for the event
     * @param event
     * @return eventDAO.updateSeatsEventInc(event)
     * @throws ServiceException
     */
    @Override
    public int updateSeatsEventInc(Event event) throws ServiceException {
    	
    	return eventDAO.updateSeatsEventInc(event);
    	
    }

}
